package in.abip.chisame;

import in.abip.chisame.model.Tentacle;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.ListView;

/**
 * Tentacle list activity
 * 
 * @author Julot
 * @since Jan 31, 2012 9:20:20 AM
 */
public class TentacleListActivity extends ChisameActivity {
	
	private int _interval = 5000; // in millisecond
	private Handler _handler;
	
	private Runnable _refreshing = new Runnable() {
		public void run() {
			refresh();
			_handler.postDelayed(_refreshing, _interval);
		}
	};
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_activity);
		populate();
		// bind();
		_handler = new Handler();
	}

	@Override
	protected void onResume() {
		super.onResume();
		_refreshing.run();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		_handler.removeCallbacks(_refreshing);
	}
	
	protected void refresh() {
		Log.d("Refresh", "Refreshing...");
	}
	
	/** Populate list by item from database. */
	protected void populate() {
		ListView list = (ListView) findViewById(R.id.list);
		ListAdapter adapter = new ListAdapter(
			this,
			R.layout.list_item_value,
			Tentacle.model().findAll()
		);
		list.setAdapter(adapter);
	}

}
